/* Copyright (c) 2010 OFXKit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#import <Foundation/Foundation.h>
#import "OFXObject.h"
#import "OFXDocumentResponse.h"
#import "AQXMLParser.h"

/**
 * @class OFXResponseParser
 * @brief Parse OFX Response
 */
@interface OFXResponseParser : OFXObject <AQXMLParserDelegate> {
  OFXDocumentResponse* document;
 
  bool inInvBankTran;
  NSString* invBankTranFundingSubAccount;
  NSString* parentElement;
  
  // current message set
  NSString* messageSet;
  NSMutableDictionary* stringTranslationTable;
  NSMutableDictionary* dateTranslationTable;
  NSMutableDictionary* numberTranslationTable;
  NSMutableDictionary* urlTranslationTable;
  NSMutableDictionary* booleanTranslationTable;
  
  NSMutableDictionary* securities;
  
  // current object being filled out.
  NSMutableArray* objectStack;
  id currentObject;
  NSString* currentElement;
}

@property(assign) bool inInvBankTran;
@property(retain) NSString* invBankTranFundingSubAccount;
@property(retain) NSString* messageSet;
@property(retain) NSMutableArray* objectStack;
@property(retain) NSMutableDictionary* securities;
@property(retain) id currentObject;
@property(retain) OFXDocumentResponse* document;
@property(retain) NSString* currentElement;
@property(retain) NSString* parentElement;
@property(retain) NSMutableDictionary* stringTranslationTable;
@property(retain) NSMutableDictionary* dateTranslationTable;
@property(retain) NSMutableDictionary* numberTranslationTable;
@property(retain) NSMutableDictionary* urlTranslationTable;
@property(retain) NSMutableDictionary* booleanTranslationTable;

- (id) initWithDocument:(OFXDocumentResponse*)ofxDocument;

- (NSDate*) parseDateFromString:(NSString*)dateString;

- (void) parserDidEndDocument:(AQXMLParser *)parser;

- (void) parser:(AQXMLParser *)parser 
didStartElement:(NSString *)elementName 
   namespaceURI:(NSString *)namespaceURI 
  qualifiedName:(NSString *)qualifiedName 
     attributes:(NSDictionary *)attributeDict;

- (void) parser:(AQXMLParser *)parser
  didEndElement:(NSString *)elementName 
   namespaceURI:(NSString *)namespaceURI 
  qualifiedName:(NSString *)qName;

- (void)parser:(AQXMLParser *)parser 
foundAttributeDeclarationWithName:(NSString *)attributeName 
    forElement:(NSString *)elementName type:(NSString *)type 
  defaultValue:(NSString *)defaultValue;

- (void)parser:(AQXMLParser *)parser foundCDATA:(NSData *)CDATABlock;

- (void)parser:(AQXMLParser *)parser foundCharacters:(NSString *)string;

- (void)parser:(AQXMLParser *)parser parseErrorOccurred:(NSError *)parseError;

@end
